<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Active extends CI_Controller {

	public function index()
	{
		echo "success";
	}
	public function add_active()
	{
		$this->load->model('active_model');
		$aciveInfo = array(
		'start_date'	=> date("Y-m-d"),
		'end_date' 		=> $this->input->post('end_date'),
		'require_sign'  => $this->input->post('require'),
		'admin'			=> '1',
		'title'			=> $this->input->post('title')
		);
		$this->active_model->add_active($aciveInfo);
		return;
	}
	public function get_active(){
		$this->load->model('active_model');
		$data['active'] = $this->active_model->get_active();
	    $data['title'] = 'active archive';
	    $this->load->view('list_active', $data);
  
	}
	public function get_activebyId(){
		$active_id = $this->input->post('activeId');
		if($active_id=='') {
			$this->load->view('show_logo');
			return;
		}
		$this->load->model('active_model');
		$data['active'] = $this->active_model->get_active($active_id);
		$data['title'] = 'active archive';
	    $this->load->view('active_result', $data);	
	}
	public function modify_active(){
		$this->load->model('active_model');
		$activeInfo = array(
		'active_id'		=> $this->input->post('active_id'),
		'start_date'	=> $this->input->post('Start_date'),
		'end_date' 		=> $this->input->post('End_date'),
		'require_sign'  => $this->input->post('require_sign'),
		'admin'			=> $this->input->post('admin'),
		'title'			=> $this->input->post('title')
		);
		if($this->active_model->modify_active($activeInfo)){
			$data['active_item'] = $this->active_model->get_active($activeInfo['active_id']);
			$this->load->view('show_modify',$data);
			return;
		}
		$data['msg']=$activeInfo['active_id']+'fail';
		$this->load->view('unittest',$data);
		return;
	}
	public function show_modify_table($sign=false){
		$this->load->helper('form');
	    $form = array(
	    	'class' => 'form', 
	    	'id' 	=> 'search');
	    echo form_open('active/show_modify_table/ture',$form);
	    echo form_input('activeId');
	    echo form_submit('search_btn', 'search!');
	    echo form_close(' ');
	    if($sign !== false){
	    	$active_id=$this->input->post('activeId');
			$this->load->model('active_model');
			$data['active_item'] = $this->active_model->get_active($active_id);
			$this->load->view('show_modify',$data);
	    }  
	}
	public function show_add_table(){
		$this->load->helper('form');
	    $user = array(
	    	'class' => 'form', 
	    	'id' 	=> 'add');
	    echo '<h3 float="center">添加活动</h3>';
	    echo form_open('active/add_active',$user);
	    echo form_label('结束时间');
	    echo form_input('end_date');
	    echo '<br/>';
   	    echo form_label('要求次数');
	    echo form_input('require');
	      echo '<br/>';
	    echo form_label('主题内容');
   	    echo form_input('title');
   	      echo '<br/>';
	    echo form_submit('mysubmit', '添加!');
	}
}
